﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Aierp.Entities;
using Aierp.SystemEntities.System;
using Aierp.Utility.Data;
using Chloe;

namespace Aierp.Repository.Implements
{
    public class RoleNavBtnsRepository : DbInstance
    {
        public List<Sys_RoleNavBtns> FindByRoles(int rolesId)
        {
            return Db.Query<Sys_RoleNavBtns>().Where(c => c.RoleId == rolesId).ToList();
        }

        public int ChangeRoles(List<Sys_RoleNavBtns> item,int rolesId)
        {
            IDbSession dbSession = Db.Session;
            try
            {
                dbSession.BeginTransaction();
                Db.Delete<Sys_RoleNavBtns>(c => c.RoleId == rolesId);
                foreach (var s in item)
                {
                    Db.Insert(s);
                }
                dbSession.CommitTransaction();
                return 1;
            }
            catch
            {
                dbSession.RollbackTransaction();
                return 0;
            }
        }
    }
}
